
    <style>
        input[type="checkbox"] {
            -webkit-appearance: none;
            background:  url(__PUBLIC__/img/shoppingmarket_quanxuan@2x.png);
            height: 18px;
            vertical-align: middle;
            width: 18px;
            background-size: 100% 100%;
        }
        input[type="checkbox"]:checked {
            background:  url(__PUBLIC__/img/shoppingmarket_gou@2x.png);
            height: 18px;
            vertical-align: middle;
            width: 18px;
            background-size: 100% 100%;
        }
    </style>
<div class="page-group">
    <div class="page" data-page="book_kind">
        <header class="bar bar-nav">
            <a onclick="window.location.href='{:U('Bag/index')}'" class="icon" style="width: 40%">
                <img src="__PUBLIC__/img/iconfont_back@2x.png" class="back_img">
            </a>
        </header>

        <div class="content doublecontent">
            <div class="waterfall book_rec_div" style="background: #FFF">
                <ul id="order_num" class="waterfall_ul" style="padding: 10px;margin: 5px 0 0 0">
                    <volist name="d" id="v">
                        <li>
                            <div class="order_each_div">
                                <!--<img src="{$v.b_logo}">-->
                                <div class="word_no_wrap">《{$v.sm}》</div>
                                <div class="word_no_wrap">{$v.zyz}<span style="float: right;">数量：{$v.rent_num}</span></div>
                            </div>
                        </li>
                    </volist>
                </ul>
            </div>
            <div class="trans_fee">
                <span>配送费用</span>
                <span class="user_info_public">快递<span id="freightfee">{$price_rent|number_format=###,2}</span>元</span>
            </div>
            <div class="trans_fee">
                <span>会员免运费（剩{$num_delivery}次）</span>
                <input class="user_info_public" id="is_ffree" type="checkbox" onclick="checkfreight(this)"/>
            </div>
            <div class="trans_fee">
                <span style="visibility: hidden">lalala</span>
                <span class="user_info_public">共<span id="total_num">{$total}</span>件商品  合计（运费）：<font class="color_book_kind_titile" id="price1">￥{$price_rent}</font></span>
            </div>
            <div class="rent_confirm_address" onclick="window.location.href='{:U("User/address")}'">
                <img src="__PUBLIC__/img/xinfen@2x.png" style="width: 100%">
                <div class="recieve_person word_no_wrap">
                    <div class="recieve_people">收货人：{$add.name}</div>
                    <div class="recieve_num">{$add.phone}</div>
                </div>
                <div class="recieve_address word_no_wrap">
                   收货地址：{$add.province}{$add.city}{$add.district}{$add.address}
                </div>
            </div>
        <div class="block_remark">
            <span>备注</span>
            <textarea name="remark" id="remark"></textarea>
        </div>
    </div>
    <nav class="bar bar-tab old_bar">
        <a class="tab-item external" href="#">
            <font color="#000">合计（运费）</font><font class="color_book_kind_titile"  id="price2">￥{$price_rent|number_format=###,2}</font>
        </a>
        <a class="tab-item external" href="#" onclick="checkover()">
            <input class="save_address" type="button" value="我要借阅">
        </a>
    </nav>
</div>
<script>
    function myinit(){
        $('#is_ffree').click();
    }
    function checkfreight($this){
        var is_checked=$this.checked;
        var price1=document.getElementById("price1");
        var price2=document.getElementById("price2");
        var freightfee=document.getElementById("freightfee").innerHTML;
        if(is_checked){
            freightfee='0.00';
        }
        price1.innerHTML="￥"+freightfee;
        price2.innerHTML="￥"+freightfee;
    }

    function checkover(){
        var phone=document.getElementsByClassName("recieve_num")[0].innerHTML;
        if(Trim(phone)==""){
            $.alert("请先填写地址");
            return;
        }
        var is_ffress=document.getElementById("is_ffree").checked;
        if(is_ffress){
            is_ffress=1;
        }else{
            is_ffress=0;
        }

        //下单前检查
        $.post('{:U("Order/rentCheck")}',{is_ffree:is_ffress,liststr:"{:I('get.liststr')}"},function(data){
            if(data.status=="success"){
                $(this).attr("onclick", "");//防止重复点击
                bear_rent("{:I('get.liststr')}",is_ffress);
            }else{
                alert(data.data);
            }
        },"json");
    }

    //产生订单
    function bear_rent($liststr,$is_ffress){
        $.post("{:U('Order/bear_order_rent')}",{liststr:$liststr,is_ffree:$is_ffress,remark:$('#remark').val()},function(data){
            if(data.status=='success'){
                Unifiedorder(data.data);
            }else{
                alert(data.data)
            }
        },'json');
    }
    //统一下单
    function Unifiedorder($pay_id){
        $.post("{:U('Order/getJsApiParameters_rent')}",{id:$pay_id},function(data){
            if(data.status=='complete'){
                alert(data.message);
                window.location.href="{:U('User/order_rent')}";
            }
            if(data.status=="error"){
                alert("无法支付，"+data.message);
            }
            if(data.status=="success"){
                callpay(data.message);
            }
        },'json');
    }

    //微信支付
    function callpay(data)
    {
        if (typeof WeixinJSBridge == "undefined"){
            if( document.addEventListener ){
                document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
            }else if (document.attachEvent){
                document.attachEvent('WeixinJSBridgeReady', jsApiCall);
                document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
            }
        }else{
            jsApiCall(data);
        }
    }

    function jsApiCall($jsApiParameters)
    {
        WeixinJSBridge.invoke(
                'getBrandWCPayRequest',
                eval('(' + $jsApiParameters + ')'),
                function(res){
                    WeixinJSBridge.log(res.err_msg);
                    //alert(res.err_code+res.err_desc+res.err_msg);
                    window.location.href="{:U('User/order_rent')}";
                }
        );
    }
</script>